home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 003 / db3tips3.arc / DB3MISC.TXT < prev    next >
Text File  |  1986-12-21  |  18KB  |  478 lines

  1.                  Preformatted dBASE SUM Command
  2.        (PC Magazine Vol 5 No 15 Sept 16, 1986 Power User)
  3.  
  4.      The dBASE SUM command reports totals of numeric fields, but its
  5. output is Spartan at best -- just the raw numbers and their field
  6. names.  If you need a presentable record of the state of your data
  7. file on a given date, it just won't do.
  8.      Here's a useful idea for transforming dBASE's Report Form
  9. capability into a a much-enhanced SUM command.  Like SUM, it rapidly
  10. totals a file; unlike SUM, however, the totals are clearly,
  11. consistently formatted with headings and date.  You don't even have
  12. to retype the long SUM command next time.
  13.      You start by making a copy of any .FRM file you've written
  14. previously.  Next, issue the MODIFY REPORT command and, at the second
  15. screen, specify " " as the Subtotal Field.  Then answer Y to the
  16. inquiry about wanting a Summary Report.  Finally, go back and remove
  17. the Subtotal Field, then save the .FRM file to disk and run it.  When
  18. you run a report modified in this way, only the headings and totals
  19. print out, saving a lot of time and paper.
  20.      Editor's Note:  This tip cons dBASE into buying Screen 2 of the
  21. Report Form.  It hustles dBASE into accepting nothing (" ") as a
  22. Subtotal Field.  (You have to make some entry there or dBASE won't
  23. give you the chance to specify Summary Report.)  If you just save the
  24. report with " " as the Subtotal Field, however, dBASE will judge that
  25. every record fits within the first subtotal group.  You'll get the
  26. right totals, but they'll be reported twice -- first as subtotals,
  27. then as totals.
  28.      However, by then modifying the Report Form by removing the " ",
  29. you further trick dBASE into suppressing the "**SUBTOTAL" line
  30. entirely.  After that, whenever you want global totals from your file,
  31. just type REPO FORM filename.
  32.      You could use this same .FRM to total segments of a file by
  33. adding a SET FILTER TO or a FOR condition.  Or you could make a
  34. permanent disk record of this nicely formatted data by adding TO FILE
  35. filename to the REPORT command.
  36.  
  37. -----------------------------------------------------------------
  38.                        1-2-3 to dBASE III
  39.        (PC Magazine Vol 5 No 15 Sept 16, 1986 Power User)
  40.  
  41.      An alternative procedure for converting 123 worksheets to dBASE
  42. III is to create a 123 print file whose range includes only the data
  43. (not the headings).  Set the left margin to 0 and the right to 240.
  44. Select Options Other Unformatted, then Go.  For best results, reset
  45. any numeric formatting options in the spreadsheet first.
  46.      Your dBASE file structure must be set up with the same field
  47. widths as the 123 columns.  The dBASE import command is:
  48.  
  49. APPEND FROM filename.PRN SDF
  50.  
  51.      Editor's Note:  The file produced by 123 is in pure ASCII format
  52. with each spreadsheet row delimited by a carriage return-line feed.
  53. Most word processors and many other applications can read this format
  54. as well.  If you find it useful to export data often, set up a 123
  55. macro.  Create and name the data cell range.  Then execute:
  56.  
  57. \RFR rangename~
  58. \RR rangename~
  59. \PF filename.PRN~
  60. \OOUML0~MR240~MT0~MB0~QAGQ
  61.  
  62. Exporting from dBASE back to 123 is as easy as typing:
  63.  
  64. COPY TO filename.TXT DELIMITED
  65.  
  66. DELIMITED causes dBASE to format the output file with each field
  67. separated by a comma and character fields enclosed in double quotes.
  68. Once back in 123, position the cursor where you want the data to drop
  69. in and type:
  70.  
  71. \FIN filename.TXT
  72.  
  73. 123 will note the commas and create the column structure accordingly,
  74. converting the quoted strings into labels.  Unfortunately, something
  75. is lost in the translation -- your formulas.  What you see is what you
  76. get.  Another potential problem is 123's unfortunate 240-character
  77. width limit for importing and exporting.  If these limits don't get in
  78. the way, however, you can switch a file back and forth between 123 and
  79. dBASE, taking advantage of each program's special strengths.
  80.      One of the advantages of the new dBASE III Plus is that it will
  81. allow you to APPEND 1-2-3 .WKS files directly.
  82.  
  83. -----------------------------------------------------------------
  84.                Printing a Field on Multiple Lines
  85.  
  86.      The following dBASE III routine can be used to print a field on
  87. multiple lines.  Each field that is passed to the program will be split
  88. into substrings of the specified length or shorter.  Words will not be
  89. split.  The substrings will be printed starting at the row/column
  90. coordinates.  Syntzx to call the program is:
  91.  
  92. DO WRAP WITH fieldname, length, row, col
  93.  
  94. * Program:  WRAP.PRG
  95. parameters string, length, row, col
  96.  
  97. strlen = LEN(string)
  98. DO WHILE strlen > length
  99.   spot = length
  100.   * Do not divide a word
  101.   DO WHILE SUBSTR (string, spot, 1) # " "
  102.     spot = spot - 1
  103.   ENDDO
  104.   @ row, col SAY SUBSTR(string, 1, spot - 1)
  105.   row = row + 1
  106.   string = SUBSTR(string, spot+1, strlen-spot)
  107.   strlen = LEN(string)
  108. ENDDO
  109. @ row, col SAY string
  110. RETURN
  111.  
  112. -----------------------------------------------------------------
  113.                           Safety First
  114.        (PC Magazine Vol 5 No 16 Sept 30, 1986 Power User)
  115.  
  116.      Before upgrading to dBASE III Plus, you should first install the
  117. program in a separate subdirectory so you can test whether your
  118. existing Version 1.1 programs will still run.  If you want to run Plus
  119. with your old programs, one immediaet change you'll want to make is to
  120. remove the STATUS=ON and HELP=ON lines from Plus's standard CONFIG.DB
  121. file.  By installing Plus in this tentative way, you can switch back
  122. to the older, tested version simply by loading it from its own
  123. directory.  Later, when you're absolutely convinced, you can deinstall
  124. both versions and put Plus on the normal directory from which you've
  125. loaded dBASE in the past.
  126.      Editor's Note:  There is far less difference between dBASE III
  127. Plus and dBASE III than between III and II.  In fact, there is very
  128. little in the new version that will cause problems with your older
  129. programs, but there are some gremlins.
  130.      For example, SET COLOR TO commands now use letters instead of
  131. numbers.  Any applications that use screen enhancements such as
  132. underline or reverse video for clarity must be revised; and, once
  133. revised, they won't run properly in the older dBASE.
  134.      Plus takes more than twice as much disk space -- up from 149K to
  135. 312K.  The old standard workstation -- a dual floppy system with dBASE
  136. and applications programs on drive A: and data on drive B: -- is
  137. strictly a thing of the past.  dBASE III Plus takes more operating
  138. memory, too.  If you have only 256K, you're up a creek; while Ashton-
  139. Tate supplies a paddle in the form of a bare-bones CONFIG.DB, memory
  140. is strictly rationed and there's little available for such memory-
  141. intensive functions as indexing and sorting.  If you couldn't work
  142. a day without resident programs like ProKey or SideKick, you're out
  143. of work until you add more RAM.
  144.      There are lots of little things to complain about.  The report
  145. and label generators are simply terrible; while adding no new
  146. capabilities, they give you much less information and require many
  147. more steps to complete the same work.  In the interactive mode, the
  148. cursor jumps to line 24 each time the dot prompt appears.  This makes
  149. it difficult or impossible to leave information on the screen while
  150. you ask questions, make replacements, etc.
  151.  
  152. -----------------------------------------------------------------
  153.                             Eyes Left
  154.         (PC Magazine Vol 5 No 20 Nov 25, 1986 Power User)
  155.  
  156.      dBASE's TRIM() function is perfect for removing trailing blanks,
  157. but neither dBASE II nor Version 1 of dBASE III offers the reverse:
  158. an easy way to trim leading blanks.  LTRIM.PRG performs this function,
  159. assuming you're working with a character field.
  160.  
  161. LTRIM.PRG:
  162.  
  163. CLEAR
  164. SET TALK OFF
  165. ACCE "LTRIM which FILE?" TO fil
  166. ACCE "REPL which FIELD?" TO fld
  167. USE &fil
  168. DO WHIL .NOT. EOF()
  169.   ref=1
  170.   DO WHIL ref<LEN(&fld)
  171.     ref2=SUBS(&fld,ref,1)
  172.     IF ref2#' '
  173.       EXIT
  174.     ELSE
  175.       ref=ref+1
  176.     ENDIF
  177.   ENDDO
  178.   REPL &fld with SUBS(&fld,ref)
  179.   ? &fld
  180.   SKIP
  181. ENDDO
  182. SET TALK ON
  183.  
  184.      Editor's Note:  dBASE III Plus solves this sometimes annoying
  185. problem by adding a direct function, LTRIM():REPL <filename) WITH
  186. LTRIM(<filename>).  This new LTRIM() applies only to character-type
  187. fields.
  188.      If you have an older version of dBASE, however, LTRIM.PRG will
  189. come in handy if, for example, you want to clean up a name field that
  190. has leading blanks, or if you need to index a file on the ZIP code
  191. and you know that some ZIPs have not been entered flush-left.
  192.      The general technique -- indexing right from the leftmost
  193. character -- can be useful in different ways.  Suppose you want to
  194. express a number flush-left, and it's inconvenient or impossible to
  195. use dBASE III's PICTURE "@B" function.  You could modify the structure
  196. of the numeric field, converting it to character format.  At this
  197. point, all the numeric data in your new character field is flush-
  198. right.  The LTRIM.PRG will eat the leading blanks, pulling the
  199. character string over to the leftmost position.
  200.      With a few changes you can even LTRIM on the fly, without
  201. modifying the data structure from numeric to character and without
  202. replacing the contents.  If you fieldname for a numeric field 8 digits
  203. wide is called "Numbr", the following routine will create a left-
  204. ustrified (and TRIMed) character string, no matter what value is in
  205. the Numbr field:
  206.  
  207. fld=STR(Numbr,8)
  208. ref=1
  209. DO WHIL fld=' ' .AND. ref<8
  210.   fld=SUBS(fld,2)
  211.   ref=ref+1
  212. ENDDO
  213. fld=TRIM(fld)
  214.  
  215. If you're LTRIMing a character field on the fly, only the first and
  216. third lines differ:
  217.  
  218. fld=chrfield
  219. ref=1
  220. DO WHIL fld=' ' .AND. ref<LEN(chrfield)
  221.   fld=SUBS(fld,2)
  222.   ref=ref+1
  223. ENDDO
  224. fld=TRIM(fld)
  225.  
  226. If you're using dBASE II, remember that the syntax to STORe memory
  227. variables is different.  The last line above would read:
  228.  
  229. STOR TRIM(fld) TO fld
  230.  
  231. -----------------------------------------------------------------
  232.                         High-Power Pause
  233.         (PC Magazine Vol 5 No 20 Nov 25, 1986 Power User)
  234.  
  235.      The procedure below gives you an easy way to display messages
  236. from with a dBASE application.  For example, if a menu offers choices
  237. of 1-9 and the user enters "k", the program would trap this impossible
  238. response as follows:
  239.  
  240. DO WHILE .T.
  241.   * insert you menu screen here
  242.   * GET user's choice and READ
  243.   IF .NOT. response $ "123456789"
  244.     DO pause WITH [No choice "]+response+["]
  245.   ELSE
  246.     EXIT
  247.   ENDIF error-trap
  248. ENDDO menu
  249.  
  250.      If the user's response is not allowable, the DO WHILE loop stays
  251. active, reprinting the menu screen and reGETting the user's response.
  252. Thus, if the user gets past your error trap, you know it's safe to
  253. process his response.
  254.      Editor's Note:  Although the PAUSE.PRG below was designed for
  255. noncritical error messages, if you pause long enough to think it
  256. through, you'll probably find a lot of other uses for this handy
  257. dBASE III procedure.  As examples, you might DO pause WITH any of
  258. the following:
  259.  
  260.      "Don't forget to backup this new data."
  261.      "Remember to invoice this extra item."
  262.      "Bob wants THREE copies of this report."
  263.      "REM each record MUST have a zip before indexing."
  264.      "Please verify coding on West Coast items."
  265.      "Verify: this check amount is over $1,000."
  266.  
  267.      PAUSE.PRG thus has a lot of horsepower under the hood for such a
  268. short procedure -- some of these might be useful in other programs you
  269. write.
  270.      For example, by passing the message as a parameter, you can send
  271. the user a context-sensitive message.  It surrounds your message with
  272. arrows and a space.  It centers the message: the expression, (80-LEN
  273. (mess))/2, asks the computer to pace off half the distance from column
  274. 39 depending on the LENgth of the current message.  (Note: maximum
  275. message length is 76 characters.)  This same line also enhances the
  276. message: unless you have SET INTENSITY OFF, the GET appears in reverse
  277. video.  Of course, you're not actually GETting anything, so the CLEAR
  278. GETS straightens that out.
  279.      PAUSE displays on the same screen line every time, so the user
  280. becomes accustomed to receiving minor error messages there.  (You could
  281. choose a different line just by changing the @24s.)  It beeps to alert
  282. the user that an unusual condition exists.
  283.      Finally, having delivered its message, PAUSE gets out of the way
  284. without requiring a keystroke.  It tidies up by erasing its message
  285. and RETUrns to the calling program.  You might even ask the user at
  286. the beginning of a session "How long do you want reminders displayed?"
  287. and STORE that number to a variable called "duration."  Then change the
  288. DO WHILEx<25 loop to DO WHILE x<duration.
  289.  
  290. * PAUSE.PRG
  291. PARA mess
  292. ? CHR(7)
  293. SET CONS OFF
  294. mess=CHR(26)+" "+mess+" "+CHR(27)
  295. @ 24,0
  296. @ 24,(80-LEN(mess))/2 GET mess
  297. CLEA GETS
  298. x=0
  299. DO WHIL x<25
  300. x=x+1
  301. ENDD x=message duration
  302. @ 24,0
  303. SET CONS ON
  304.  
  305. -----------------------------------------------------------------
  306.                       dBASE Subdirectories
  307.              (PC World Star-Dot-Star November 1986)
  308.  
  309.      Subdirectories make organizing your hard disk a breeze because
  310. you can put related data and programs into logical places.  dBASE III
  311. Plus lacks a simple command to change the current directory.
  312.      It's possible to use the command RUN CD path to accommodate this
  313. end, but that requires additional memory, plus extra time to load the
  314. DOS command interpreter.  Fortunately, dBASE III Plus can easily load
  315. and execute assembly language programs.  CD.PRG and CD.BIN use this
  316. feature to change the current directory.  CD.PRG closes any open data
  317. files, loads the assembly language program CD.BIN into memory,
  318. transfers control to CD.BIN, then eliminates CD.BIN from memory and
  319. returns control to the calling program.
  320.      Use DEBUG to create CD.BIN as shown below.  Store both CD.PRG and
  321. CD.BIN in the same subdirectory that contains dBASE III Plus.  To use
  322. the programs, simply issue the command DO CD WITH path, replacing path
  323. with the appropriate subdirectory specification.
  324.  
  325. * CD.PRG
  326. parameter dir
  327. close databases
  328. load cd
  329. call cd with dir
  330. ? 'Directory now changed to ',dir
  331. release cd
  332. return
  333.  
  334. CD.BIN:
  335. A>DEBUG
  336. -A 100
  337. XXXX:0100 MOV DX,BX
  338. XXXX:0102 MOV AX,3B00
  339. XXXX:0105 INT 21
  340. XXXX:0107 RETF
  341. XXXX:0108
  342. -N CD.BIN
  343. CX 0000
  344. :8
  345. -W
  346. -Q
  347.  
  348. -----------------------------------------------------------------
  349.                      dBASE Cross Tabulation
  350.         (PC Magazine Vol 5 No 22 Dec 23, 1986 Power User)
  351.  
  352.      Occasionally, you need COUNTs for all possible combinations of
  353. certain fields in dBASE files.  Multiway tabulation (e.g., "How are
  354. people in a database distributed by sex and age?") is a fairly common
  355. tool in statistics, and it is sometimes seen in other contexts.  To do
  356. this with a series of COUNTs or TOTALs, however, requires that the
  357. whole sequence of instructions be assembled from scratch for each
  358. specific query.
  359.      XTAB.PRG offers a more general solution, though it can process
  360. only one table at a time.  To use the program, issue the command:
  361.  
  362. DO XTAB
  363.  
  364. The procedure GETs the data filename, the number of variables (i.e.,
  365. fields or expressions) to be tabulated, and the name of each one.
  366. Then it creates a summary database to store the resulting table (ending
  367. in .DBX) and begins processing.
  368.      Editor's Note:  Life would be simpler if dBASE would allow you to
  369. TOTAL ON more than one field.  Then, to your original file you could
  370. just add a numeric field caller counter (a length of 4 would usually
  371. be sufficient), REPL ALL counter WITH 1,INDEX ON key expression, and
  372. TOTAL ON key expression.
  373.  
  374. ** XTAB.PRG
  375. SET TALK OFF
  376. CLEAR
  377. nvar=0
  378. origfile=SPAC(20)
  379. @  3,0 SAY "CROSS TAB PROGRAM"
  380. @  5,0 SAY "Which file? " GET origfile
  381. READ
  382. origfile=TRIM(origfile)
  383. @  7,0 SAY "How many variables?" GET nvar
  384. READ
  385. SELE 1
  386. USE &origfile ALIA origfile
  387. keyexp=""
  388. * keyexp = list of vars delimited with plus signs
  389. i=1
  390. DO WHILE i<=nvar .AND. LEN(keyexp)<250
  391.   nomvar=SPAC(25)
  392.   @ 8+i,0 SAY "Variable "+STR(i,2)+" field/expression? " GET nomvar
  393.   READ
  394.   nomvar=TRIM(nomvar)
  395.   IF TYPE([&nomvar})='N'
  396.     * Note: change below if decimals
  397.     keyexp=keyexp+'STR('+nomvar+',10,0)'
  398.   ELSE
  399.     keyexp=keyexp+nomvar
  400.   ENDIF
  401.   IF i<nvar
  402.     keyexp=keyexp+"+[ ]+"
  403.   ENDIF
  404.   i=i+1
  405. ENDDO
  406. * create summary file
  407. SET SAFE OFF
  408. COPY STRU EXTENDED TO tempsum
  409. SELE 2
  410. USE tempsum
  411. DELE FOR RECNO()>2
  412. PACK
  413. GOTO 1
  414. REPL field_name WITH "TOT",field_type WITH "N",;
  415.      field_len WITH 5,field_dec WITH 0
  416. sumname=TRIM(origfile)+".dbx"
  417. CREATE &sumname FROM tempsum
  418. USE &sumname
  419. ERAS tempsum.dbf
  420. * scanning the data file
  421. ? "Standby ....processing"
  422. SELE 1
  423. INDEX ON &keyexp TO temp
  424. SET INDEX TO temp
  425. SET SAFE ON
  426. keyref=&keyexp
  427. DO WHILE .NOT. EOF()
  428.   COUN WHILE &keyexp=keyref TO ncount
  429.   SELE 2
  430.   APPEND BLANK
  431.   REPL tot WITH ncount,key WITH keyref
  432.   SKIP
  433.   SELE 1
  434.   keyref=&keyexp
  435. ENDDO
  436. CLEAR
  437. SELE 2
  438. DISP OFF ALL tot,key
  439. CLOSE DATA
  440. * Optional: ERAS temp.ndx
  441. SET TALK ON
  442. RETU
  443.  
  444. -----------------------------------------------------------------
  445.                          Flexible Signal
  446.         (PC Magazine Vol 5 No 22 Dec 23, 1986 Power User)
  447.  
  448.      When running a long dBASE process, you want to know when it's
  449. through so you can do something else in the meantime.  The short
  450. SIGNAL.PRG is loud enough to be heard from the next room.  Some users
  451. might like to add a WAIT statement at the end.
  452.  
  453. * SIGNAL.PRG
  454. ? CHR(7)+TIME()
  455. ?? CHR(7)+" - Process Complete."
  456. ?? CHR(7)
  457. ?? CHR(7)
  458. ?? CHR(7)
  459. ?? CHR(7)
  460. ?? CHR(7)
  461. ?? CHR(7)
  462.  
  463.      Editor's Note:  If signaling is useful in your dBASE programs,
  464. you may want to develop this theme.  For example, by combining The
  465. Norton Utilities with dBASE's RUN capability, you could signal a major
  466. error with an SOS in Morse code thus:
  467.  
  468.     RUN BEEP /f4000 /r3 /d1
  469.     RUN BEEP /f4000 /r3 /d3
  470.     RUN BEEP /f4000 /r3 /d1
  471.  
  472. A musically minded user may want to announce that he's ready to start
  473. his process with:
  474.  
  475.     RUN BEEP /f1000 /r3 /d1
  476.     RUN BEEP /f800 /d8
  477.  
  478.